package org.example.socket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class SocketClient {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("localhost", 8899);
        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();
        String sendMsg = "client send massage";
        // 发送消息到服务器端
        outputStream.write(sendMsg.getBytes());

        // 接收服务器端消息
        byte[] message = new byte[2048];
        int len = inputStream.read(message);
        System.out.println("发送给服务端的消息：" + sendMsg);
        System.out.println("从服务端接收的消息：" + new String(message, 0, len));
        socket.close();
    }
}
